package collection2;

import lombok.AllArgsConstructor;
import lombok.Data;

import java.util.Comparator;
import java.util.TreeSet;

public class orderSet1 {

    public static void main(String[] args) {
        //实现排序
//        TreeSet<User> set1 = new TreeSet<>(Comparator.comparingInt(User::getAge));
        TreeSet<User> set1 = new TreeSet<>();
        set1.add(new User("ytt",18));
        set1.add(new User("yt",16));
        set1.add(new User("cy",17));
        System.out.println(set1);

        User user = set1.pollLast();
        System.out.println(set1);

    }


}
@Data
@AllArgsConstructor
 class User implements Comparable<User>{

    private String name;
    private Integer age;


    @Override
    public int compareTo(User o) {
        return this.age - o.age;
    }
}
